function RF_Target = RF_TTM(Data, Date_Target, TTM_Target)
% The code is based on the following paper:
%   Chen, T. Y., Lin, Y. L., and Tzeng, L. Y., forthcoming.
%   Estimating probability weighting functions through option pricing bounds. Review of Asset Pricing Studies.
%
% Copyright: Tzu-Ying Chen, Yo-Lan Lin, Larry Y. Tzeng
% Date: January 30, 2024

[AllPair, ~, Index_Pair] = unique([Date_Target TTM_Target], 'rows');
for d = 1:size(AllPair, 1)
    for i = 0:10
        Index = find(Data(:, 1)==str2num(datestr(datenum(num2str(AllPair(d, 1)), 'yyyymmdd') - i, 'yyyymmdd')));      
        if length(Index) > 0
            Data_TTM = Data(Index, 2);
            Data_RF = Data(Index, 3);
            break
        else
        end
    end
    clear Index       

    RF_Pair(d, 1) = interp1(Data_TTM, Data_RF, AllPair(d, 2), 'linear');   
    clear Data_TTM Data_RF
end
RF_Target = RF_Pair(Index_Pair);
end